#!/bin/bash

#requires: all_tests
#requires: not make
#requires: petsc

BOUT_TOP=../../..
export PATH=$(pwd)/$BOUT_TOP/bin:$PATH

error=0

failed=
for target in $(find $BOUT_TOP/examples/ -name makefile)
do
    dir=$(dirname ${target})
    if grep ":.*requires_petsc" $target -q;
    then
        echo "Trying to compile ${dir}"

        (cd ${dir} && make 2>&1)
        ex=$?

        if test $ex -gt 0
        then
            echo $(basename $dir) failed
            error=1
            failed="$failed\n$(basename $dir) failed"
        fi
    else
        echo "Skipping $dir - requires PETSc"
    fi
done

echo -e $failed

exit $error
